package main

import (
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/bsonrw"
	"go.mongodb.org/mongo-driver/bson/bsontype"
)

type ShipIDType string

type Ship struct {
	ID ShipIDType
}

func ParseShipID(s string) (ShipIDType, error) {
	return ShipIDType(s), nil
}

func (id *ShipIDType) UnmarshalBSONValue(t bsontype.Type, data []byte) error {
	var s string
	vr := bsonrw.NewBSONValueReader(t, data)
	d, err := bson.NewDecoder(vr)
	if err != nil {
		return err
	}
	err = d.Decode(&s)
	if err != nil {
		return err
	}
	v, err := ParseShipID(s)
	if err != nil {
		return err
	}
	*id = v
	return nil
}
